home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / internet / wsockspy.zip / WSOCK32.DOC < prev   
Text File  |  1996-04-12  |  9KB  |  256 lines

  1. WSOCK32 Winsock Spy Facility
  2. Version .91 By Walt Howard
  3. April 12, 1996
  4. Email: walth@netcom.com
  5.  
  6. WSOCK32 spy is a personal tool I am making available free to WINSOCK
  7. programmers worldwide. I would appreciate bug reports and feedback to
  8. make it the best product possible. I will make source code available
  9. once I'm sure it is of high enough quality.
  10.  
  11. QUICK SETUP
  12. -----------
  13.  
  14. 0) WSOCK32 only monitors 32 bit, Windows 95 applications. It will
  15. definitely NOT work with 16bit WINSOCK apps, and though I haven't tried
  16. it, I highly doubt it will work with Win32s, or NT.
  17.  
  18. 1) Copy this special, spy enabled WSOCK32.DLL to the directory where the
  19. EXE file you want to spy on resides.
  20.  
  21. 2) Set the following environment variables:
  22.  
  23. SET WSOCK_LOG=LOG
  24. SET WSOCK_FLAGS=s
  25.  
  26. 3) Normally windows installs the standard WSOCK32.DLL at
  27. C:\WINDOWS\SYSTEM\WSOCK32.DLL. If your setup is different, set the
  28. following environment variable to where your standard WSOCK32.DLL DOES
  29. exist:
  30.  
  31. SET WSOCK_PATH=<the full path to your WSOCK32.DLL>
  32.  
  33. 4) Execute your WINSOCK app
  34.  
  35. 5) You should get a message box notifying you that logging is on.
  36.  
  37. 6) Exit your WINSOCK app
  38.  
  39. 7) Look for a file called LOG.xxx where xxx is a 3 digit hex
  40. number.
  41.  
  42. 8) That file will contain the log of your winsock session. Treasure it
  43. for all time.
  44.  
  45. WHY WSOCK32
  46. -----------
  47.  
  48. While getting familiar with the WINSOCK API is not trivial, it is easy
  49. when compared to learning the myriad protocols built on top of it like
  50. SMTP, POP3, NNTP, FTP, TELNET, NFS, NTP, etc.
  51.  
  52. The RFC ( Request for Clarification?) documents the govern the standards
  53. are complete, but too complete for a beginner. Without experience it is
  54. difficult to tell what parts of a protocol are important, and what are
  55. not.
  56.  
  57. WSOCK32 lets you spy on professional WINSOCK apps and shows you exactly
  58. what some of the best programmers in the world are doing with WINSOCK.
  59. You will VERY rapidly cut right to the chase and see exactly how NNTP,
  60. SMPT, TELNET and FTP among others, work.
  61.  
  62. It will also aid you in debugging your own apps.
  63.  
  64. WSOCK32 is NOT a full debugger. It is merely a way to jump start your
  65. WINSOCK programming months or years ahead.
  66.  
  67. HOW IT WORKS
  68. ------------
  69.  
  70. WSOCK32.DLL is a dll that "slips between" your 32 bit, WINDOWS 95
  71. application and the REAL WSOCK32.DLL. WSOCK32.DLL spy intercepts the
  72. calls to Winsock and outputs trace information that tells you each
  73. WINSOCK call made and some relevant information about it. WSOCK32 does
  74. NOT work with old 16 bit Winsock. It doesn't interfere. It just doesn't
  75. even know that kind of app is running because it is tracing the
  76. WSOCK32.DLL, NOT the WINSOCK.DLL.
  77.  
  78. To use WSOCK32, place it in the directory that contains the executeable
  79. you want to trace. The point being that you want that program to load
  80. THIS WSOCK.DLL before finding the standard WSOCK32.DLL
  81.  
  82. OPTIONS
  83. -------
  84.  
  85. Since WSOCK32 is a DLL, there is no way to control it via command line
  86. options. Control is facilitated by the use of environment variables.
  87.  
  88. Before executing the program you want to trace, you must set one or more
  89. of the following environment variables.
  90.  
  91. WSOCK_LOG=<logfile>
  92. -------------------
  93.  
  94. IMPORTANT!!! This is a MANDATORY option. Without it, WSOCK32 will NOT
  95. output any debug information. This is the switch that turns logging on.
  96.  
  97. Whatever value you give, WSOCK32 will construct a log file by appending
  98. 3 digits of the process id of the process you are tracing.
  99.  
  100. EXAMPLE:
  101.  
  102. SET WSOCK_LOG=C:\TRACE\LOG will place logging information into files
  103. in the C:\TRACE directory, and they will all be LOG.* such as LOG.34a,
  104. LOG.F1C, etc.
  105.  
  106. If you need to watch the trace output in realtime you will need to get
  107. the WSOCK32 PRO PACKAGE (which I just thought of this minute so don't hold
  108. your breath). In the meantime you have several options. The DOS "type"
  109. command will dump the contents of the trace file, even though it is open
  110. for write. You can view it that way, or copy it to another file like this:
  111. "type LOG.34b >savefile".
  112.  
  113. The UNIX tail command will continuously read a file and keep dumping it
  114. to the screen as it is growing. Use the -f option i.e. tail -f LOG.43a
  115. If you don't know UNIX you might want to start getting familiar with it
  116. as a large percentage of your interaction with WINSOCK might end up
  117. being with UNIX TCPIP programs.
  118.  
  119. WSOCK_FLAGS=<single character options>
  120. --------------------------------------
  121.  
  122. This is a string of single, lower case characters, that modify some
  123. aspect of WSOCK32 behavior. You would specify it like this:
  124.  
  125. SET WSOCK_FLAGS=sfdt
  126.  
  127. f = Flush trace information immediately, don't buffer.
  128. d = NoData. Don't show the data stream, just the WINSOCK calls
  129. s = Show source of data stream for send/recv/sendto/recvfrom calls
  130. i = Log inbound data only
  131. o = Log outbound data only
  132. q = Suppress notification message box
  133. n = No binary data. Don't show non alphanumeric bytes
  134. t = Display Timing Marks (millisecond resolution)
  135. h = Display High Resolution Timing Marks (microsecond resolution)
  136.  
  137. Unless the "n" option is set, WSOCK32 shows unprintable characters as
  138. their hex value, preceeded by a # sign. For example, #ff would be 0xff.
  139. I used the # because both 0x and \x (the normal C hex signifiers) each
  140. have two characters; very bothersome when you have pages and pages of
  141. hex ouput.
  142.  
  143. Timing marks appear between brackets with "ms" for milliseconds and "u"
  144. for microseconds:
  145.  
  146. <3978087ms>
  147. <8682674566u>
  148.  
  149. If the "n" option is set, binary data is just summarized between { and
  150. }. If 16 unprintable characters came through, it would print as {16}.
  151.  
  152. WSOCK_PATH=<path of REAL wsock32.dll>
  153. -------------------------------------
  154.  
  155. WSOCK32 traps your API calls, outputs information about them, then relays
  156. them to the REAL WSOCK32.DLL. It uses LoadLibrary to load the REAL
  157. WSOCK32.DLL. By default, it will load C:\WINDOWS\SYSTEM\WSOCK32. If your
  158. REAL WSOCK32.DLL is in a different directory than that, you need to set
  159. this environment variable to its full pathname.
  160.  
  161. TRACE FILE
  162. ----------
  163. The trace file WSOCK32 creates shows each WSOCK32.DLL function call
  164. with a little relevant information. Calls appear in square brackets
  165. [] with socket number, :, callname, information and (return code). Like
  166. this:
  167.  
  168. [SOCKET:FUNCTIONNAME: data (RETURN VALUE)]
  169.  
  170. or an example:
  171.  
  172. [8:connect: 204.236.30.2.119 (-1)]
  173.  ^ ^        ^                 ^
  174.  | |        Information       Return Value
  175.  | Function Name
  176.  Socket Handle
  177.  
  178. Here is an example of a trace of AGENT, a popular WINSOCK mail reader,
  179. doing its thing. (My notes are in PARENTHESES () and would not appear
  180. in a normal trace)
  181. ---------------------------------------------------------------------
  182.  
  183. [WSAStartup (0)]        (WSAStartup gets called, return value 0)
  184. [socket: 7]             (the socket call allocated socket number 7)
  185. [7:setsockopt (0)]      (set socket options of socket 7 )
  186. [getservbyname]         (standard stuff, etc)
  187. [socket: 8]
  188. [8:setsockopt (0)]
  189. [inet_addr: news.alt.net (0xffffffff)]  (???? I don't know)
  190. [WSAAsyncGetHostByName: news.alt.net]   (attempt to get ip address)
  191. [8:WSAAsyncSelect: HWND:78c msg:1037 mask:59 (0)]
  192.                 (VERY import WINSOCK function so I display ALL
  193.                         the parameters)
  194. [8:connect: 204.236.30.2.119 (-1)]
  195.         (connect return a -1, a fail)
  196. [WSAGetLastError: (10035)]
  197. [getservbyname]
  198. [socket: 15]
  199. [15:setsockopt (0)]
  200. [inet_addr: netcom.com (0xffffffff)]
  201. [WSAAsyncGetHostByName: netcom.com]
  202. [WSAGetLastError: (10035)]
  203. [8:recv]<-200 Mail info@alt.net for info about $5/month NNTP access (posting ok).
  204.         (we just contacted the news server, now it gets interesting)
  205. [8:send]->MODE READER
  206.         (hmmm! interesting NNTP command)
  207. [WSAGetLastError: (10035)]
  208. [15:WSAAsyncSelect: HWND:78c msg:1037 mask:59 (0)]
  209. [15:connect: 192.100.81.100.110 (-1)]
  210. [WSAGetLastError: (10035)]
  211. [WSAIsBlocking (false)]
  212. [8:recv]<-200 news.alt.net InterNetNews NNRP server INN 1.4unoff2 7-Aug-95 ready (posting ok).
  213. [8:send]->AUTHINFO USER hoser   (log into the NNTP server)
  214. [WSAGetLastError: (10035)]
  215. [WSAGetLastError: (10035)]
  216. [WSAIsBlocking (false)]
  217. [WSAIsBlocking (false)]
  218. [8:recv]<-381 PASS required
  219. [8:send]->AUTHINFO PASS bozo    (give it a password)
  220. [WSAGetLastError: (10035)]
  221. [15:recv]<-+OK UCB Pop server (version 1.831beta) at netcom starting.
  222.         (log into a POP server)
  223. [15:send]->USER yomomma
  224. [WSAGetLastError: (10035)]
  225. [8:recv]<-281 Ok
  226. [8:send]->GROUP alt.bite.me
  227. [WSAGetLastError: (10035)]
  228. [15:recv]<-+OK Password required for yomomma
  229. [15:send]->PASS YoMommabeaho
  230. [WSAGetLastError: (10035)]
  231. [WSAIsBlocking (false)]
  232. [WSAIsBlocking (false)]
  233. [15:recv]<-+OK yomomma has 0 message(s) (0 octets).
  234.  
  235. DEVELOPER NOTES
  236. ---------------
  237.  
  238. As I've delivered it, the compilation will result in 15 warnings about
  239. the return types being different levels of indirection. That is OK. This
  240. is not a problem. It is because the return value of GetProcAddress is a
  241. FARPROC and manually casting it to the proper value negates the value of
  242. the generic macro DYNAPROC.
  243.  
  244. BUGS
  245. ----
  246.  
  247. For some reason PING will not work using this DLL.
  248.  
  249. I have not done extensive testing at all with this as I don't use ALL
  250. the WINSOCK functions. Please be sure to send me notification of any
  251. problems with enough info to allow me to reproduce the problem.
  252.  
  253. Walt Howard
  254. Email: walth@netcom.com
  255.  
  256.